﻿@using DIS.Infrastructure.Entities.Entity;
@{
    ViewBag.Title = "市内交通费明细";
    Layout = "~/Views/Shared/_Layout.cshtml";

    List<FinancialPeriod> yearmonth = ViewBag.YearMonth;
    User user = ViewBag.User;
    CityTaxi cityTaxi = ViewBag.cityTaxi;
    List<CityTaxiDetail> cityTaxiDetails = ViewBag.cityTaxiDetails;
    int cityTaxiId = cityTaxi == null ? 0 : cityTaxi.Id;
    List<Project> projects = ViewBag.projects;
}
@section head{
    <script type="text/javascript">
        function feesum() {
            var sumfee = 0;
            $("input[id='taxfee']").each(function () {
                var fee = $(this).val();
                sumfee = sumfee + fee * 1;
            });

            //$('#totalfee').val(sumfee);
            $('#stotalfee').html(sumfee);
        }

        function invoicesum() {
            var sumcount = 0;
            $("input[id='invoicecount']").each(function () {
                var fee = $(this).val();
                sumcount = sumcount + fee * 1;
            });

           // $('#totalcount').val(sumcount);
            $('#stotalcount').html(sumcount);
        }

        function yearMonthSelect() {
            // var obj = $("#selyearmonth");
            var obj = document.getElementById("selyearmonth");
            var date = obj.options[obj.selectedIndex].value;

            $('#fillDate').html("(" + date.split('$')[1] + ")");
        }
    </script>
}
<form name="saveuserForm" action="/Reimbursement/SaveCityTaxiFee" method="post">

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#D6D6D6">
    <tr>
        <td height="19" background="/content/img/tbg.gif" bgcolor="#E7E7E7">
            <table width="96%" border="0" cellspacing="1" cellpadding="1">
                <tr>
                    <td style="padding-left: 10px;">
                        <b><strong>市内交通费明细</strong></b>
                    </td>
                    <td align="right">
                        <b><strong><a href="/Reimbursement/CityTaxiFee">市内交通费列表</a></strong></b>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td align="center" valign="top" bgcolor="#FFFFFF">
            <input type="hidden" id="issubmit" name="state" value="0" />
            <input type="hidden" id="MainId" name="MainId" value="@cityTaxiId" />
            <table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D6D6D6">
                <tr height="30px">
                    <td colspan="7" align="left">
                        <strong>勘察记录表</strong>&nbsp;&nbsp;<select name="selyearmonth" id="selyearmonth" onchange="yearMonthSelect()">
                            <option value="无">请选择</option>
                            @{
                                string filldate = "";
                                if (yearmonth != null && yearmonth.Any())
                                {
                                    foreach (var item in yearmonth)
                                    {
                                        string sdateStr = DateTime.Parse(item.StartDate).ToString("yyyy年MM月dd日");
                                        string edateStr = DateTime.Parse(item.EndDate).ToString("yyyy年MM月dd日");

                                        if (cityTaxi != null && cityTaxi.Year == item.Year && cityTaxi.Month == item.Month)
                                        {
                                            filldate = "(" + sdateStr + "-" + edateStr + ")";
                                <option value="@(item.Year):@(item.Month):@(item.StartDate):@(item.EndDate)$@(sdateStr)-@(edateStr)" selected>@item.Year-@item.Month</option>
                                        }
                                        else
                                        {
                                <option value="@(item.Year):@(item.Month):@(item.StartDate):@(item.EndDate)$@(sdateStr)-@(edateStr)">@item.Year-@item.Month</option>
                                        }
                                    }
                                }
                            }
                        </select><span id="fillDate">@filldate</span>&nbsp;&nbsp;&nbsp;&nbsp;
                        <strong>项目名称</strong>&nbsp;&nbsp;<select name="projectId" id="projectId">
                        <option value="0">请选择</option>
                        @{
                            if(projects!=null&&projects.Count>0)
                            {
                                foreach(var item in projects)
                                {
                                    if(cityTaxi!=null&&cityTaxi.project.Id==item.Id)
                                    {
                                        <option value="@item.Id" selected>@item.ProjectCode (@item.ProjectName)</option>
                                    }
                                    else
                                    {
                                    <option value="@item.Id">@item.ProjectCode (@item.ProjectName)</option>
                                    }
                                }
                            }
                        }
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="7">
                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
                            <thead>
                                <tr  bgcolor="#FBFCE2">
                                    <td width="10%" height="30" align="center">
                                        姓名
                                    </td>
                                    <td width="20%" height="30" align="center">
                                        勘察日期
                                    </td>
                                    <td width="20%" height="30" align="center">
                                        出差地点
                                    </td>
                                    <td width="25%" height="30" align="center">
                                        勘察站名
                                    </td>
                                    <td width="10%" height="30" align="center">
                                        出租车费
                                    </td>
                                    <td width="10%" height="30" align="center">
                                        发票数
                                    </td>
                                    <td width="5%" height="30" align="center">
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    if (cityTaxiDetails != null && cityTaxiDetails.Count > 0)
                                    {
                                        int j = 0;
                                        foreach (var item in cityTaxiDetails)
                                        {
                                    <tr bgcolor="#FFFFFF" align="center">
                                        <td height="30" align="center">@user.RealName
                                        <input type="hidden" name="Id" value="@item.Id" />
                                        </td>
                                        <td align="center">
                                            <input  name="reconnaissancedate" id="reconnaissancedate" value="@item.ReconnaissanceDate" type="text"  onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" style="width: 95%" />
                                        </td>
                                        <td align="center">
                                            <input type="text" name="businessaddress" value="@item.TravelAddress" id="businessaddress" style="width: 95%"  />
                                        </td>
                                        <td align="center">
                                            <input name="reconnaissancename" type="text" value="@item.ReconnaissanceName" id="reconnaissancename" style="width: 95%" />
                                        </td>
                                        <td align="center">
                                            <input  name="taxfee" type="text" value="@item.TaxiFee" id="taxfee" onkeyup="feesum()" style="width: 90%" />
                                        </td>
                                        <td align="center">
                                            <input  name="invoicecount" type="text" value="@item.InvoiceCount" id="invoicecount" onkeyup="invoicesum()" style="width: 90%" />
                                        </td>
                                        <td align="center">
                                            @{if (j == 0)
                                              {
                                            <a href="javascript:;" class="addTr">[+]</a>
                                              }
                                              else
                                              {
                                                  <a href="javascript:;" class="removeTr">[-]</a>
                                              }

                                            }
                                        </td>
                                    </tr>
                                              j++;
                                        }
                                    }
                                    else
                                    {
                                        <tr bgcolor="#FFFFFF" align="center" >
                                    <td height="30" align="center">@user.RealName
                                    <input type="hidden" name="Id" value="0" />
                                    </td>
                                    <td align="center">
                                        <input name="reconnaissancedate" id="reconnaissancedate" value="" type="text" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
                                            style="width: 95%" />
                                    </td>
                                    <td align="center">
                                        <input type="text" name="businessaddress" value="" id="businessaddress" style="width: 95%" />
                                    </td>
                                    <td align="center">
                                        <input name="reconnaissancename" type="text" value="" id="reconnaissancename" style="width: 95%" />
                                    </td>
                                    <td align="center">
                                        <input name="taxfee" type="text" value="" id="taxfee" onkeyup="feesum()" style="width: 90%" />
                                    </td>
                                    <td align="center">
                                        <input name="invoicecount" type="text" value="" id="invoicecount" onkeyup="invoicesum()" style="width: 90%" />
                                    </td>
                                    <td align="center">
                                        <a href="javascript:;" class="addTr">[+]</a>
                                    </td>
                                </tr>
                                    }
                                }
                                
                            </tbody>
                            <tfoot>
                             <tr bgcolor="#FBFCE2" align="center" class="hover">
                    <td width="10%" align="center">
                        <font><b>合计</b></font>
                    </td>
                    <td width="20%">
                        &nbsp;
                    </td>
                    <td width="20%">
                        &nbsp;
                    </td>
                    <td width="25%">
                        &nbsp;
                    </td>
                    <td width="10%">
                    @{
                        if (cityTaxi != null)
                        {
                                <span name="stotalfee" id="stotalfee" value="0">@cityTaxi.TaxiFee</span>
                        }
                        else
                        {
                                <span name="stotalfee" id="stotalfee" value="0">0.00</span>
                        }
                       }
                    </td>
                    <td width="10%">
                    @{
                        if (cityTaxi != null)
                        {
                            <span name="stotalcount" id="stotalcount" value="0">@cityTaxi.InvoiceCount</span>
                        }
                        else
                        {
                            <span name="stotalcount" id="stotalcount" value="0">0</span>
                        }
                        }
                        
                    </td>
                    <td width="5%">
                        &nbsp;
                    </td>
                </tr>
                            </tfoot>
                        </table>
                    </td>
                </tr>
               
                <tr bgcolor="#FFFFFF" align="center" class="hover">
                    <td align="left" colspan="7">
                        <b><font style="color: red">说明：本表作为每月报销差旅费附件。</font></b>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td align="center">
            <input class="new_save" value="保存" type="Submit" />
            <input class="new_submit" value="提交" type="Submit" />
        </td>
    </tr>
</table>
<span id="moban" style="display:none"><tr bgcolor="#FFFFFF" align="center" >
                                    <td height="30" align="center">@user.RealName
                                    <input type="hidden" name="Id" value="0" />
                                    </td>
                                    <td align="center">
                                        <input name="reconnaissancedate" id="reconnaissancedate" value="" type="text" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
                                            style="width: 95%" />
                                    </td>
                                    <td align="center">
                                        <input type="text" name="businessaddress" value="" id="businessaddress" style="width: 95%" />
                                    </td>
                                    <td align="center">
                                        <input name="reconnaissancename" type="text" value="" id="reconnaissancename" style="width: 95%" />
                                    </td>
                                    <td align="center">
                                        <input name="taxfee" type="text" value="" id="taxfee" onkeyup="feesum()" style="width: 90%" />
                                    </td>
                                    <td align="center">
                                        <input name="invoicecount" type="text" value="" id="invoicecount" onkeyup="invoicesum()" style="width: 90%" />
                                    </td>
                                    <td align="center">
                                        <a href="javascript:;" class="removeTr">[-]</a>
                                    </td>
                                </tr></span>
</form>
@section tail{
    <script type="text/javascript">
        $('.addTr').live('click', function () {

            str = $(this).parent().parent().html();
            str = str.replace('addTr', 'removeTr');
            str = str.replace('[+]', '[-]');
           // str = $("#moban").html();
            $(this).parent().parent().parent().append('<tr  bgcolor="#FFFFFF">' + str + '</tr>');
            //$(this).parent().parent().parent().append(str);
            feesum();
            invoicesum();
        });

        $('.removeTr').live('click', function () {
            $(this).parent().parent().remove();
            feesum();
            invoicesum();
            return false;
        });
        $('.new_save').click(function () {
            $('#issubmit').attr('value', 0);
            return true;
        });
        $('.new_submit').click(function () {
            $('#issubmit').attr('value', 1);
            return true;
        });
        
    </script>
}
